// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Bumper Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 15 : TYPE_BUMPER

// Function declarations
reserve function Bumper_DebugDraw
reserve function Bumper_DebugSpawn

// Static Values

// Tables

function Bumper_DebugDraw
	DrawSprite(0)
end function


function Bumper_DebugSpawn
	temp5 = 15
	temp4 = 0
	CallFunction(DebugMode_SpawnObject)
	object[arrayPos0].drawOrder = 4
end function


event ObjectMain
	if object.state > 0
		object.frame = object.value0
		object.frame /= 5
		object.frame++
		object.value0++
		if object.value0 > 22
			object.value0 = 0
			object.state = 0
			object.frame = 0
		end if
	end if
	if object.outOfBounds == 1
		object.priority = PRIORITY_ACTIVE_BOUNDS
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_Function10)
		BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			if object.state == 0
				PlaySfx(SfxName[Bumper], 0)
			end if
			if object.value0 > 5
				PlaySfx(SfxName[Bumper], 0)
			end if
			object.state = 1
			object.priority = PRIORITY_ACTIVE
			temp0 = object[currentPlayer].xpos
			temp0 -= object.xpos
			temp1 = object[currentPlayer].ypos
			temp1 -= object.ypos
			ATan2(temp2, temp0, temp1)
			Cos256(temp0, temp2)
			Sin256(temp1, temp2)
			temp0 *= 0x700
			temp1 *= 0x700
			object[currentPlayer].value1 = 0
			object[currentPlayer].value12 = temp0
			object[currentPlayer].value13 = temp1
			object[currentPlayer].speed = object.xvel
			object[currentPlayer].gravity = GRAVITY_AIR
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_Function9)
	DrawSpriteXY(object.frame, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-14, -14, 28, 28, 1, 401)
	SpriteFrame(-12, -12, 24, 24, 1, 430)
	SpriteFrame(-16, -16, 32, 32, 30, 401)
	SpriteFrame(-12, -12, 24, 24, 1, 430)
	SpriteFrame(-16, -16, 32, 32, 30, 401)
	SpriteFrame(-16, -16, 32, 32, 30, 401)
	SetTableValue(TypeName[Bumper], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(Bumper_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Bumper_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-14, -14, 28, 28, 1, 401)
end event
